home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-11-10 | 22.5 KB | 780 lines |
- /******************************************************************************/
- /**
- International Microcomputer Software Inc. @1997 -- Rob Mayfield
- This applet is a demonstration of the use of the IMSI SDK using Java.
- It takes advantage of the Microsoft extension to Java using OLE.
- It uses Microsoft's Variant class (com.ms.com.Variant) and connects
- to the OLE server which can be either an inproc server (IMSIGX40.DLL) or
- the local server (TCW40.EXE).
- The main work for the SDK classes are done by the DrawingCanvas class
- which handles the mouse action, repaint and calls which must interface to
- the IMSI server.
-
- **** Must be run currently in Microsoft IExplorer or jview application viewer ****
- to run: jview SDKDemo.class
-
- ImageButton and VisualCafe by Symantec Corp. 1997
- Ole and COM classes by Microsoft Corp. 1997
-
- version 1.0 March 31, 1997
- */
- /******************************************************************************/
-
- import java.applet.*;
- import java.awt.*;
- import SDKDemoFrame;
- import DrawingCanvas;
- import mImageButton;
- import symantec.itools.awt.*;
-
- /*
- Main Class for applet SDKDemo
- */
- public class SDKDemo extends Applet
- {
-
- // main entry for application
- public static void main(String args[])
- {
-
- frame = new SDKDemoFrame("SDKDemo");
-
- // Must show Frame before we size it so insets() will return valid values
- frame.show();
- frame.hide();
- frame.resize(frame.insets().left + frame.insets().right + 619,
- frame.insets().top + frame.insets().bottom + 514);
-
- //frame.resize(619, 514);
-
- SDKDemo appSDKDemo = new SDKDemo();
-
- frame.add("Center", appSDKDemo);
- appSDKDemo.m_fStandAlone = true;
- appSDKDemo.init();
-
- appSDKDemo.start();
- frame.show();
-
- }
-
- // SDKDemo Class Constructor
- public SDKDemo()
- {
- }
-
- void ComboBoxDrawings_Selected(Event event)
- {
- theDrawingCanvas.setButtonDown(NONECLICK);
- notifyAllImageButtons(NONECLICK);
-
- // display selected item in combobox
- String fName = ComboBoxDrawings.getSelectedItem();
- if (fName != null)
- fName = theDrawingCanvas.OpenDrawing(fName); // open the drawing and use SDK to paint on the canvas
- // toggle all buttons to unclicked state
- }
-
- void ButtonFindDrawings_Clicked(Event event)
- {
- if (event.modifiers == Event.META_MASK)
- { System.out.println("handleEvent: " + event.toString()); // this event never happens as regular right clicks on a button are xed
- }
- else
- {
- theDrawingCanvas.setButtonDown(NONECLICK);
- notifyAllImageButtons(NONECLICK); // set all buttons to up
-
- // find the drawing in file list, using SDK to load and display
- String fName = theDrawingCanvas.OpenDrawing(null);
- if (fName != null) ComboBoxDrawings.addItem(fName);
- //ComboBoxDrawings.select();
- //ComboBoxDrawings.reshape(220,8,252,21); // if we don't put this reshape here the combobox will shrink to the size of the longest string
- }
- }
-
- void ButtonCursor_Action(Event event)
- {
- if (event.modifiers == Event.META_MASK)
- {
- String Str = helpStrings.General;
-
- (new ViewSourceDialog(frame, false, Str)).show();
-
- }
- else
- {
- if (ButtonCursor.getBevelHeight() == 0)
- {
- ButtonCursor.setBevelHeight(2);
- theDrawingCanvas.setButtonDown(NONECLICK);
- }
- else
- {
- ButtonCursor.setBevelHeight(0);
- theDrawingCanvas.setButtonDown(PICKCLICK);
- }
-
- notifyAllImageButtons(PICKCLICK);
- }
- }
-
- void ButtonStar_Action(Event event)
- {
-
- if (ButtonStar.getBevelHeight() == 0)
- {
- theDrawingCanvas.setButtonDown(NONECLICK);
- ButtonStar.setBevelHeight(2);
- }
- else
- {
- theDrawingCanvas.setButtonDown(STARCLICK);
- ButtonStar.setBevelHeight(0);
- }
-
- notifyAllImageButtons(STARCLICK);
- }
-
- void ButtonSpline_Action(Event event)
- {
-
- if (ButtonSpline.getBevelHeight() == 0)
- {
- theDrawingCanvas.setButtonDown(NONECLICK);
- ButtonSpline.setBevelHeight(2);
- }
- else
- {
- theDrawingCanvas.setButtonDown(SPLINECLICK);
- ButtonSpline.setBevelHeight(0);
- }
-
- notifyAllImageButtons(SPLINECLICK);
-
- }
-
- void ButtonLine_Action(Event event)
- {
-
- if (ButtonLine.getBevelHeight() == 0)
- {
- theDrawingCanvas.setButtonDown(NONECLICK);
- ButtonLine.setBevelHeight(2);
- }
- else
- {
- theDrawingCanvas.setButtonDown(LINECLICK);
- ButtonLine.setBevelHeight(0);
- }
-
- notifyAllImageButtons(LINECLICK);
- }
-
- void ButtonCircle_Action(Event event)
- {
- if (ButtonCircle.getBevelHeight() == 0)
- { ButtonCircle.setBevelHeight(2); // set button to up state
- theDrawingCanvas.setButtonDown(NONECLICK);
- }
- else // click button and set it to 'down' state
- {
- theDrawingCanvas.setButtonDown(CIRCLECLICK);
- ButtonCircle.setBevelHeight(0);
- }
-
- notifyAllImageButtons(CIRCLECLICK);
- }
-
- void ButtonProperties_Clicked(Event event)
- {
- theDrawingCanvas.displayProperties();
- notifyAllImageButtons(NONECLICK);
-
- }
-
- void ButtonNew_Clicked(Event event)
- {
- //fName = theDrawingCanvas.OpenDrawing(fName);
- theDrawingCanvas.NewDrawing();
- theDrawingCanvas.setButtonDown(NONECLICK);
- notifyAllImageButtons(NONECLICK);
- }
-
- void ButtonZoomPlus_Clicked(Event event)
- {
- theDrawingCanvas.ZoomPlus();
- }
-
- void ButtonZoomMinus_Clicked(Event event)
- {
- theDrawingCanvas.ZoomMinus();
- }
-
- void verticalScrollbar_ScrollLineUp(Event event)
- {
- theDrawingCanvas.VScrollLineUp();
- }
- void verticalScrollbar_ScrollLineDown(Event event)
- {
- theDrawingCanvas.VScrollLineDown();
- }
- void verticalScrollbar_ScrollPageUp(Event event)
- {
- theDrawingCanvas.VScrollPageUp();
- }
- void verticalScrollbar_ScrollPageDown(Event event)
- {
- theDrawingCanvas.VScrollPageDown();
-
- }
-
- void horizontalScrollbar_ScrollLineUp(Event event)
- {
- theDrawingCanvas.HScrollLineUp();
- }
- void horizontalScrollbar_ScrollLineDown(Event event)
- {
- theDrawingCanvas.HScrollLineDown();
- }
- void horizontalScrollbar_ScrollPageUp(Event event)
- {
- theDrawingCanvas.HScrollPageUp();
- }
- void horizontalScrollbar_ScrollPageDown(Event event)
- {
- theDrawingCanvas.HScrollPageDown();
-
- }
-
-
- public void notifyAllImageButtons(int From)
- { /*
- This code simulates a group button set, where only one button is down
- at one time and that button stays down until it is clicked again
- or another in the group is clicked.
- */
- switch (From)
- { case CIRCLECLICK:
- ButtonLine.setBevelHeight(2);
- ButtonLine.repaint();
-
- ButtonSpline.setBevelHeight(2);
- ButtonSpline.repaint();
-
- ButtonStar.setBevelHeight(2);
- ButtonStar.repaint();
-
- ButtonCursor.setBevelHeight(2);
- ButtonCursor.repaint();
-
- ButtonCircle.repaint();
- break;
-
- case LINECLICK:
- ButtonCircle.setBevelHeight(2);
- ButtonCircle.repaint();
-
- ButtonSpline.setBevelHeight(2);
- ButtonSpline.repaint();
-
- ButtonStar.setBevelHeight(2);
- ButtonStar.repaint();
-
- ButtonCursor.setBevelHeight(2);
- ButtonCursor.repaint();
-
- ButtonLine.repaint();
- break;
-
- case SPLINECLICK:
- ButtonCircle.setBevelHeight(2);
- ButtonCircle.repaint();
-
- ButtonLine.setBevelHeight(2);
- ButtonLine.repaint();
-
- ButtonStar.setBevelHeight(2);
- ButtonStar.repaint();
-
- ButtonCursor.setBevelHeight(2);
- ButtonCursor.repaint();
-
- ButtonSpline.repaint();
- break;
-
- case STARCLICK:
- ButtonCircle.setBevelHeight(2);
- ButtonCircle.repaint();
-
- ButtonLine.setBevelHeight(2);
- ButtonLine.repaint();
-
- ButtonSpline.setBevelHeight(2);
- ButtonSpline.repaint();
-
- ButtonCursor.setBevelHeight(2);
- ButtonCursor.repaint();
-
- ButtonStar.repaint();
- break;
-
- case PICKCLICK:
- ButtonCircle.setBevelHeight(2);
- ButtonCircle.repaint();
-
- ButtonLine.setBevelHeight(2);
- ButtonLine.repaint();
-
- ButtonSpline.setBevelHeight(2);
- ButtonSpline.repaint();
-
- ButtonStar.setBevelHeight(2);
- ButtonStar.repaint();
-
- ButtonCursor.repaint();
- break;
-
- case NONECLICK:
- ButtonCircle.setBevelHeight(2);
- ButtonCircle.repaint();
-
- ButtonLine.setBevelHeight(2);
- ButtonLine.repaint();
-
- ButtonSpline.setBevelHeight(2);
- ButtonSpline.repaint();
-
- ButtonStar.setBevelHeight(2);
- ButtonStar.repaint();
-
- ButtonCursor.setBevelHeight(2);
- ButtonCursor.repaint();
-
- break;
-
- }
- }
-
- public boolean mouseDown(Event evt, int x, int y)
- {
- if (evt.modifiers == Event.META_MASK)
- {
- // Create and show as not modal
- (new ViewSourceDialog(frame, false, helpStrings.General)).show();
- return true;
- }
- return false;
- }
-
- public void init()
- {
- super.init();
-
- // We set no layout manager. We want exact placement (we could use GridBagLayout also, but it has redraw problems.).
- setLayout(null);
- //resize(619,514); // set the applet size
- // applet size come from frame
- setBackground(new Color(0xC0C0C0)); // light gray color
-
-
- // load the five image buttons. Here we use the Symantec ImageButton class
- //ButtonCursor = new symantec.itools.awt.ImageButton();
- ButtonCursor = new mImageButton();
- ButtonCursor.reshape(483,34,26,24);
- add(ButtonCursor);
- ButtonCursor.setBevelHeight(2);
-
- // We need to find the base URL to find the images to load button images. In applet we use
- // getDocumentBase(). In Frames we use the getProperty()
- if (m_fStandAlone == true)
- docBase = "file:///" + System.getProperty("user.dir").replace('\\', '/');
- else
- docBase = null;
-
- try
- {
- // load from the same URL base as applet or application
- if (m_fStandAlone == true)
- {
- ButtonCursor.setImageURL(new java.net.URL(docBase + "/cursor.gif"));
- }
- else
- {
- ButtonCursor.setImageURL(new java.net.URL(getDocumentBase(), "./cursor.gif"));
- }
- }
- catch (java.net.MalformedURLException error)
- {
- StatusBox.setText("error in URL");
- }
- ButtonCursor.setScaleMode(true);
- ButtonStar = new mImageButton();
- ButtonStar.reshape(440,34,26,24);
- add(ButtonStar);
- ButtonStar.setBevelHeight(2);
- try
- {
- if (m_fStandAlone == true)
- {
- ButtonStar.setImageURL(new java.net.URL(docBase + "/star.gif"));
- }
- else
- {
- ButtonStar.setImageURL(new java.net.URL(getDocumentBase(), "./star.gif"));
- }
- }
- catch (java.net.MalformedURLException error)
- {
- StatusBox.setText("error in URL");
- }
- ButtonStar.setScaleMode(true);
- ButtonSpline = new mImageButton();
- ButtonSpline.reshape(412,34,26,24);
- add(ButtonSpline);
- ButtonSpline.setBevelHeight(2);
- try
- {
- if (m_fStandAlone == true)
- {
- ButtonSpline.setImageURL(new java.net.URL(docBase + "/spline.gif"));
- }
- else
- {
- ButtonSpline.setImageURL(new java.net.URL(getDocumentBase(), "./spline.gif"));
- }
- }
- catch (java.net.MalformedURLException error)
- {
- StatusBox.setText("error in URL");
- }
- ButtonSpline.setScaleMode(true);
- ButtonLine = new mImageButton();
- ButtonLine.reshape(384,34,26,24);
- add(ButtonLine);
- ButtonLine.setBevelHeight(2);
- try
- {
- if (m_fStandAlone == true)
- {
- ButtonLine.setImageURL(new java.net.URL(docBase + "/line.gif"));
- }
- else
- {
- ButtonLine.setImageURL(new java.net.URL(getDocumentBase(), "./line.gif"));
- }
- }
- catch (java.net.MalformedURLException error)
- {
- StatusBox.setText("error in URL");
- }
- ButtonLine.setScaleMode(true);
- ButtonCircle = new mImageButton();
- ButtonCircle.reshape(356,34,26,24);
- add(ButtonCircle);
- ButtonCircle.setBevelHeight(2);
- try
- {
- if (m_fStandAlone == true)
- {
- ButtonCircle.setImageURL(new java.net.URL(docBase + "/circle.gif"));
- }
- else
- {
- ButtonCircle.setImageURL(new java.net.URL(getDocumentBase(), "./circle.gif"));
- }
-
- }
- catch (java.net.MalformedURLException error)
- {
- StatusBox.setText("error in URL");
- }
- ButtonCircle.setScaleMode(true); // set the buttton to scale the image to fit
-
- // put the other button on the applet
- ButtonProperties = new java.awt.Button("Properties");
- ButtonProperties.reshape(270,38,68,18);
- add(ButtonProperties);
- ButtonNew = new java.awt.Button("New");
- ButtonNew.reshape(210,38,50,18);
- add(ButtonNew);
- ButtonZoomPlus = new java.awt.Button("Zoom +");
- ButtonZoomPlus.reshape(150,38,50,18);
- add(ButtonZoomPlus);
- ButtonZoomMinus = new java.awt.Button("Zoom -");
- ButtonZoomMinus.reshape(90,38,50,18);
- add(ButtonZoomMinus);
- ButtonFindDrawings = new java.awt.Button("Find Drawing");
- ButtonFindDrawings.reshape(125,10,88,18);
- add(ButtonFindDrawings);
-
- ComboBoxDrawings = new java.awt.Choice();
- add(ComboBoxDrawings);
- ComboBoxDrawings.reshape(220,8,252,21);
-
- /*
- Add theDrawingCanvas to the form. This will be the active drawing
- surface to which the IMSI SDK will interact. The DrawingCanvas class
- is derived from Canvas and overides the paint and mouse events.
- */
- theDrawingCanvas = new DrawingCanvas(this);
- theDrawingCanvas.reshape(7,68, bounds().width - 12, bounds().height - 105); // 95
- theDrawingCanvas.setBackground(new Color(0xFFFFFF)); // white background
- add(theDrawingCanvas);
-
- // horizontal scroll bars
- horizontalScrollbar = new java.awt.Scrollbar(Scrollbar.HORIZONTAL);
- horizontalScrollbar.reshape(insets().left + 204,insets().top + 497,210,16);
- horizontalScrollbar.setBackground(new Color(0xFFFFFF));
- horizontalScrollbar.setValues(0, 1, 0, 100);
- horizontalScrollbar.setLineIncrement(1);
- horizontalScrollbar.setPageIncrement(10);
- add(horizontalScrollbar);
-
- // verticle scroll bars
- verticalScrollbar = new java.awt.Scrollbar(Scrollbar.VERTICAL);
- verticalScrollbar.reshape(insets().left + 603,insets().top + 159,16,198);
- verticalScrollbar.setBackground(new Color(0xFFFFFF));
- verticalScrollbar.setValues(0, 1, 0, 100);
- verticalScrollbar.setLineIncrement(1);
- verticalScrollbar.setPageIncrement(10);
- add(verticalScrollbar);
-
- StatusBox = new java.awt.TextField();
- StatusBox.setEditable(false);
- StatusBox.reshape(4, theDrawingCanvas.bounds().y + theDrawingCanvas.bounds().height + 2,
- bounds().width - 8, 21);
- add(StatusBox);
-
- frame.setParent(this);
- }
-
- // Handle the events from the buttons and Combobox
- public boolean handleEvent(Event event)
- {
- if (event.target == ButtonZoomMinus && event.id == Event.ACTION_EVENT)
- {
- ButtonZoomMinus_Clicked(event);
- return true;
- }
- if (event.target == ButtonZoomPlus && event.id == Event.ACTION_EVENT)
- {
- ButtonZoomPlus_Clicked(event);
- return true;
- }
- if (event.target == ButtonNew && event.id == Event.ACTION_EVENT)
- {
- ButtonNew_Clicked(event);
- return true;
- }
- if (event.target == ButtonProperties && event.id == Event.ACTION_EVENT)
- {
- ButtonProperties_Clicked(event);
- return true;
- }
- if (event.target == ButtonCircle && event.id == Event.ACTION_EVENT)
- {
- ButtonCircle_Action(event);
- return true;
- }
- if (event.target == ButtonLine && event.id == Event.ACTION_EVENT)
- {
- ButtonLine_Action(event);
- return true;
- }
- if (event.target == ButtonSpline && event.id == Event.ACTION_EVENT)
- {
- ButtonSpline_Action(event);
- return true;
- }
- if (event.target == ButtonStar && event.id == Event.ACTION_EVENT)
- {
- ButtonStar_Action(event);
- return true;
- }
- if (event.target == ButtonCursor && event.id == Event.ACTION_EVENT)
- {
- ButtonCursor_Action(event);
- return true;
- }
- if (event.target == ButtonFindDrawings && event.id == Event.ACTION_EVENT)
- {
- ButtonFindDrawings_Clicked(event);
- return true;
- }
- if (event.target == ComboBoxDrawings && event.id == Event.ACTION_EVENT)
- {
- ComboBoxDrawings_Selected(event);
- return true;
- }
-
- if (event.target == verticalScrollbar && event.id == Event.SCROLL_LINE_UP)
- {
- verticalScrollbar_ScrollLineUp(event);
- return true;
- }
-
- if (event.target == verticalScrollbar && event.id == Event.SCROLL_LINE_DOWN)
- {
- verticalScrollbar_ScrollLineDown(event);
- return true;
- }
-
- if (event.target == verticalScrollbar && event.id == Event.SCROLL_PAGE_UP)
- {
- verticalScrollbar_ScrollPageUp(event);
- return true;
- }
-
- if (event.target == verticalScrollbar && event.id == Event.SCROLL_PAGE_DOWN)
- {
- verticalScrollbar_ScrollPageDown(event);
- return true;
- }
-
-
- if (event.target == horizontalScrollbar && event.id == Event.SCROLL_LINE_UP)
- {
- horizontalScrollbar_ScrollLineUp(event);
- return true;
- }
-
- if (event.target == horizontalScrollbar && event.id == Event.SCROLL_LINE_DOWN)
- {
- horizontalScrollbar_ScrollLineDown(event);
- return true;
- }
-
- if (event.target == horizontalScrollbar && event.id == Event.SCROLL_PAGE_UP)
- {
- horizontalScrollbar_ScrollPageUp(event);
- return true;
- }
-
- if (event.target == horizontalScrollbar && event.id == Event.SCROLL_PAGE_DOWN)
- {
- horizontalScrollbar_ScrollPageDown(event);
- return true;
- }
-
- return super.handleEvent(event);
- }
-
-
- // Applet info
- public String getAppletInfo()
- {
- return "Name: SDKDemo\r\n" +
- "Author: Rob Mayfield, IMSI @1997\r\n" +
- "ImageButton by Symantec Corp.\r\n" +
- "Ole and COM implemented by Microsoft Corp.\r\n" +
- "";
- }
-
- public void destroy()
- {
- // Set all vars to null to make sure that the reference counts are decremented
- // to release server application
-
- if (theDrawingCanvas.m_IDrawings != null)
- theDrawingCanvas.m_IDrawings.Close(); // close any open TC file
-
- // it is good practice to release the obtained interfaces in reverse or
- // to how they were obtained, although for Java, that is up to the virual
- // machines garbage collection.
- theDrawingCanvas.m_ITheView = null;
- theDrawingCanvas.m_IViews = null;
- theDrawingCanvas.m_ITheDrawing = null;
- theDrawingCanvas.m_IDrawings = null;
- theDrawingCanvas.m_IApp = null;
-
- }
-
- public void paint(java.awt.Graphics g)
- {
- // draw a 3D border around screen and Drawing area. Shows 3D in all environments
- theDrawingCanvas.reshape(7,68, bounds().width - 28, bounds().height - 108);
- StatusBox.reshape(4, theDrawingCanvas.bounds().y + theDrawingCanvas.bounds().height + 16,
- bounds().width - 8, 21);
-
- // reset size of scrollbar
- horizontalScrollbar.reshape(bounds().width/2 - 105,
- theDrawingCanvas.bounds().y + theDrawingCanvas.bounds().height + 1 ,210, 16);
- verticalScrollbar.reshape(bounds().width - 20,
- theDrawingCanvas.bounds().y + (theDrawingCanvas.bounds().height/2) - 99, 16, 198);
-
- // draw a quick and dirty 3D border around edge of frame
- Rectangle rec = this.bounds();
- g.setColor(Color.white);
- g.drawRect(0, 0, rec.width-3, rec.height-3);
- g.drawRect(0, 0, rec.width-2, rec.height-2);
- g.setColor(Color.darkGray);
- g.drawRect(2, 2, rec.width-3, rec.height-3);
-
- g.setColor(Color.darkGray);
- g.draw3DRect(5, 66, bounds().width - 26, bounds().height - 105, false);
-
- }
-
- public void start()
- {
- }
-
- public void stop()
- {
-
- }
-
- private boolean m_fStandAlone = false;
-
- String fName; // file name
- public static SDKDemoFrame frame;
-
- String docBase = null;
-
- //symantec.itools.awt.ImageButton ButtonCursor;
- mImageButton ButtonCursor;
- mImageButton ButtonStar;
- mImageButton ButtonSpline;
- mImageButton ButtonLine;
- mImageButton ButtonCircle;
-
- java.awt.Button ButtonProperties;
- java.awt.Button ButtonNew;
- java.awt.Button ButtonZoomPlus;
- java.awt.Button ButtonZoomMinus;
- java.awt.Button ButtonFindDrawings;
- java.awt.TextField StatusBox;
- java.awt.Choice ComboBoxDrawings;
-
- // the DrawingCanvas is a subclass of Canvas and contains all the IMSI SDK actions
- DrawingCanvas theDrawingCanvas;
- java.awt.Scrollbar horizontalScrollbar;
- java.awt.Scrollbar verticalScrollbar;
-
- // Constants used to distinguise actions in DrawingCanvas
- public static final int NONECLICK = 0;
- public static final int CIRCLECLICK = 1;
- public static final int LINECLICK = 2;
- public static final int SPLINECLICK = 3;
- public static final int STARCLICK = 4;
- public static final int PICKCLICK = 5;
-
- public static final int ZOOMMINUSCLICK = 6;
- public static final int ZOOMPLUSCLICK = 7;
- public static final int NEWCLICK = 8;
- public static final int FILELOADCLICK = 9;
-
- public static final int HORZSCROLLDOWN = 10;
- public static final int HORZSCROLLPGDN = 11;
- public static final int VERTSCROLLDOWN = 12;
- public static final int VERTSCROLLPGDN = 13;
-
- public static final int HORZSCROLLUP = 14;
- public static final int HORZSCROLLPGUP = 15;
- public static final int VERTSCROLLUP = 16;
- public static final int VERTSCROLLPGUP = 17;
- public static final int THUMB_MOVE = 18;
-
- }
-